package com.xca.touchdemo;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.xca.touchdemo.base.BaseActivity;
import com.xca.touchdemo.view.MultiTouchView;
import com.xca.touchdemo.view.TouchView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener , View.OnTouchListener {
    private static final String TAG = "MainActivity";
    private TouchView mTouchView ;
    private MultiTouchView mMultiTouchView ;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTouchView = findViewById(R.id.touch_view);
        mMultiTouchView = findViewById(R.id.multiTouchView) ;
        mTouchView.setOnClickListener(this);
        mMultiTouchView.setOnClickListener(this);
    }

//与onCreate方法互换
//    @Override
//    public int getLayoutId(){
//        return R.layout.activity_main ;
//    }
//
//    @Override
//    public void init(){
//        mTouchView = findViewById(R.id.touch_view);
//        mTouchView.setOnClickListener(this);
//    }

    @Override
    public void onClick(View v) {
        Log.d(TAG, "onClick: *****************************Click");
        Intent intent = new Intent(MainActivity.this , SignatureActivity.class) ;
        startActivity(intent);
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent event){
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "dispatchTouchEvent: ===============down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "dispatchTouchEvent: ================move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "dispatchTouchEvent: ================up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "dispatchTouchEvent: ===============cancel");
                break;
        }
        return super.dispatchTouchEvent(event);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event){
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~~Down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~Move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~Up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "onTouchEvent: ~~~~~~~~~~~~~~~~~~~~~cancel");
                break;
        }
        return super.onTouchEvent(event) ;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "onTouch: ~~~~~~~~~~~~~~~~~~~~~~Down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "onTouch: ~~~~~~~~~~~~~~~~~~~~~Move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "onTouch: ~~~~~~~~~~~~~~~~~~~~~Up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "onTouch: ~~~~~~~~~~~~~~~~~~~~~cancel");
                break;
        }
        return false;
    }
}